package com.siyuanren.gcocp.web;

import com.siyuanren.gcocp.common.web.bean.Result;
import com.siyuanren.gcocp.dto.*;
import com.siyuanren.gcocp.entity.WxCourseLive;
import com.siyuanren.gcocp.entity.WxUserCourse;
import com.siyuanren.gcocp.service.CourseService;
import com.siyuanren.gcocp.util.VaildUtil;
import com.siyuanren.gcocp.vo.*;
import com.siyuanren.gcocp.web.wx.BaseWxController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by   anxing
 * Project_name gcocp-parent
 * Path         com.siyuanren.gcocp.web.wx
 * Date         2018/4/11
 * Time         10:57
 * Description  课程相关控制器
 */
@Slf4j
@Controller
@RequestMapping("course")
public class CourseController extends BaseWxController {
    @Autowired
    CourseService courseService;

    /**
     * 返回轮播图
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("getBanners")
    @ResponseBody
    public Result getBanners() throws Exception {
        List<WxBannerDTO> banners = courseService.getBanners(getUserId());
        return new Result(banners);
    }

    /**
     * 返回主页推荐直播列表
     */
    @RequestMapping("getHomeLives")
    @ResponseBody
    public Result getHomeLives() throws Exception {
        List<WxCourseLive> homeLives = courseService.getHomeLives(getUserId());
        return new Result(homeLives);
    }

    /**
     * 返回首页推荐课程列表
     *
     * @return
     */
    @RequestMapping(value = "getRecommendCourses")
    @ResponseBody
    public Result getRecommendCourses() throws Exception {
        List<WxCategoryDTO> recommendCourses = courseService.getRecommendCourses(getUserId());
        return new Result(recommendCourses);
    }

    @ResponseBody
    @RequestMapping(value="getCourseByCategory")
    public Result getCourseByCategory(QueryCourseByCategoryVO vo) throws Exception {
        VaildUtil.check(vo);
        vo.setUserId(getUserId());
        List<WxCourseDTO> list = courseService.getCourseByCategory(vo);
        return new Result(list);
    }

    /**
     * 返回课程列表
     *
     * @return
     */
    @RequestMapping(value = "list_course")
    @ResponseBody
    public Result listCourse(QueryUserCourseVO queryUserCourseVO) throws Exception {
        VaildUtil.check(queryUserCourseVO);
        queryUserCourseVO.setUserId(getUserId());
        WxUserCourseListDTO courseListDTO = courseService.getUserCourseList(queryUserCourseVO);
        return new Result(courseListDTO);
    }

    /**
     * 提交课程进度
     *
     * @param userCourse
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("submitCourseProgress")
    public Result submitCourseProgress(WxUserCourse userCourse) throws Exception {
        VaildUtil.check(userCourse);
        userCourse.setUserId(getUserId());
        courseService.submitCourseProgress(userCourse);
        return new Result();
    }

    /**
     * 获取毕业信息
     *
     * @param queryGradVO
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("getCourseGrad")
    public Result getCourseGrad(QueryGradVO queryGradVO) throws Exception {
        VaildUtil.check(queryGradVO);
        queryGradVO.setUserId(getUserId());
        CourseGradDTO gradDTO = courseService.getCourseGrad(queryGradVO);
        return new Result(gradDTO);
    }

    /**
     * 获取微信入群二维码
     * @param queryWxGroup
     * @return
     */
    @ResponseBody
    @RequestMapping("getWxGroupQrcode")
    public Result getWxGroupQrcode(QueryWxGroupVO queryWxGroup) throws Exception {
        VaildUtil.check(queryWxGroup);
        queryWxGroup.setUserId(getUserId());
        WxGroupQrcodeDTO wxGroupQrcode = courseService.getWxGroupQrcode(queryWxGroup);
        return new Result(wxGroupQrcode);
    }

    /**
     *  获取课程详情
     */
    @RequestMapping("getCourseDetail")
    @ResponseBody
    public Result getCourseDetail(QueryCourseDetailVO queryDetailVO) throws Exception {
        queryDetailVO.setUserId(getUserId());
        CourseDetailDTO courseDetail = courseService.getCourseDetail(queryDetailVO);

        return new Result(courseDetail);
    }
}
